<template>
  <div
    class="home-middle1"
    @mouseenter="showNavigation = true"
    @mouseleave="showNavigation = false"
  >
    <div class="home-middle1-content">
      <div class="home-middle1-wrap">
        <div class="index__hd">
          <h2 class="index__tit"><i class="icon_txt"></i></h2>
        </div>
        <a class="all-play"
          ><el-icon class="all-play-icon"><VideoPlay /></el-icon>播放全部</a
        >
      </div>
      <div class="mod_index_tab">
        <a
          class="index_tab__item"
          :class="{ active: homeStore.lan == lan.lan }"
          v-for="lan in homeStore.newSongLanList"
          :key="lan.tjreport"
          >{{ lan.lan }}</a
        >
      </div>
    </div>

    <Carousel
      class="home-middle1-carousel"
      :data="forCarouselData"
      :showNavigation="showNavigation"
      comName="newSongs"
      :options="{ slidesPerView: 1, slidesPerGroup: 1 }"
    >
      <template #default="{ data }">
        <div class="new-song-list">
          <ul>
            <li
              class="new-song-item"
              v-for="(item, index) in data"
              :key="item.id"
            >
              <div class="debutlist__item_box">
                <a
                  href="javascript:;"
                  class="debutlist-img-box"
                  @click="playMusic(item)"
                >
                  <i class="mod_cover__icon_play"></i>
                  <img class="debutlist__pic" :src="item.imgUrl" />
                </a>
                <div class="debutlist__cont">
                  <h3 class="debutlist__song">
                    <a href="/n/ryqq/songDetail/003EcXXA1PLlVN">{{
                      item.name
                    }}</a>
                  </h3>
                  <p class="debutlist__author">
                    <a
                      class="c_tx_thin"
                      title="ENHYPEN (엔하이픈)"
                      href="/n/ryqq/singer/004CMy4p14LIy1"
                      >{{
                        item.singer
                          .map((s: NewSongList_SingerType) => s.title)
                          .join()
                      }}</a
                    >
                  </p>
                </div>
                <div class="debutlist__time c_tx_thin">03:16</div>
              </div>
            </li>
          </ul>
        </div>
      </template>
    </Carousel>
  </div>
</template>

<script lang="ts">
export default {
  name: 'MusicHome',
}
</script>

<script lang="ts" setup>
import Carousel from '@/components/Carousel/index.vue'
import { VideoPlay } from '@element-plus/icons-vue'
import { reactive, ref, watch } from 'vue'
import { useHomeStore } from '@/stores/homeStore'
import { getImgurlApi } from '@/api/home/getRecommendApi'
import type {
  NewSongListType,
  NewSongList_SingerType,
} from '@/stores/homeStoreType'
import { useMusicPlayStore } from '@/stores/playliststore'

const homeStore = useHomeStore() //获取数据
const playStore = useMusicPlayStore()
const showNavigation = ref(false)
const forCarouselData = ref<NewSongListType[][]>([])
watch(
  () => homeStore.newSongList,
  (val) => {
    for (let i = 0; i < val.length; i += 9) {
      forCarouselData.value.push(val.slice(i, i + 9))
    }
  }
)
const playMusic = (item: any) => {
  console.log(item.songMid)
  playStore.getMusicPlay(item.songMid)
}
</script>

<style scoped>
.debutlist__song,
.debutlist__author {
  width: 190px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.active {
  color: #31c27c;
}
.mod_cover__icon_play {
  position: absolute;
  width: 86px;
  height: 86px;
  top: 50%;
  transform: translateY(-50%);
  left: 0px;
  background-image: url('./imgs/cover_play.56974e6f.png');
  background-size: 35px 35px;
  background-repeat: no-repeat;
  background-position: center center;
  background-color: rgba(0, 0, 0, 0.2);
  opacity: 0;
  transition: 0.3s;
  cursor: pointer;
  z-index: 999;
}
.mod_cover__icon_play:hover {
  opacity: 1;
  background-size: 45px 45px;
}
.mod_cover__icon_play:hover + img {
  transform: scale(1.05);
}
.debutlist-img-box {
  width: 86px;
  height: 86px;
  overflow: hidden;
}
.debutlist__pic {
  width: 86px;
  height: 86px;
  vertical-align: middle;
  transform-origin: 43px 43px;
  transition: 0.5s;
}
.new-song-list {
  height: 1230px;
  height: 333px;
}
.new-song-list ul {
  float: left;
  width: 1230px;
  overflow: hidden;
}
.new-song-item {
  display: inline-block;
  height: 111px;
  box-sizing: border-box;
  align-items: center;
  padding-top: 12px;
  border-bottom: #eee solid 1px;
  margin-right: 30px;
  margin-bottom: -1px;
}
.debutlist__item_box {
  width: 380px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: relative;
}
.debutlist__cont {
  margin-left: -50px;
}
.all-play {
  position: absolute;
  left: 0;
  padding: 0 23px 0 43px;
  border: 1px solid #ccc;
  line-height: 38px;
  border-radius: 2px;
  font-size: 14px;
  cursor: pointer;
}
.all-play:hover {
  background-color: #eee;
}
.all-play-icon {
  position: absolute;
  font-size: 24px;
  color: #999;
  top: 50%;
  margin-top: -12px;
  left: 12px;
}
.home-middle1 {
  background-image: linear-gradient(#f2f2f2, #fff);
  min-width: 1200px;
  height: 577px;
  box-sizing: border-box;
  position: relative;
  overflow: hidden;
}
.home-middle1-content {
  width: 1200px;
  margin: 0 auto;
}
.home-middle1-wrap {
  padding: 50px 0 24px 0;
  position: relative;
}
.index__hd {
  position: relative;
}
.index__tit {
  display: block;
  margin: 0 auto;
  width: 196px;
  height: 40px;
  background-image: url('./imgs/index_tit.ee334dbf.png');
  background-position-y: -49px;
}
.mod_index_tab {
  text-align: center;
  height: 50px;
}
.mod_index_tab a {
  margin: 0 20px;
  font-size: 15px;
  cursor: pointer;
}
.mod_index_tab a:hover {
  color: #31c27c;
}
</style>
